package vip.zhenzicheng.service;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import vip.zhenzicheng.domain.User;

/**
 * @author zhenzicheng
 * @date 2023-02-23 19:16
 */
@Service
public class OrderService {

  @Autowired
  private RestTemplate restTemplate;

  @DubboReference
  private UserService userService;

  public String createOrder() {
    String remoteUserUrl = "http://localhost:8081/user/root";
    User user = restTemplate.getForObject(remoteUserUrl, User.class);
    System.out.println("创建订单");
    assert user != null : "用户不存在";
    return user + " 订单创建成功";
  }

  public String createOrderByDubbo() {
    User user = userService.getUser("root");
    System.out.println("使用dubbo创建订单");
    return user + " 订单创建成功";
  }
}
